from django.db import models


# Create your models here.

# 定义一个用户模型类

# 用户实名认证
class UserAuthModel(models.Model):
    # 真实姓名
    name = models.CharField(max_length=50, null=True, blank=True)
    # 性别
    gender = models.CharField(max_length=10, null=True, blank=True)
    # 民族
    ethnicity = models.CharField(max_length=10, null=True, blank=True)
    # 出生日期
    birth_date = models.DateField(null=True, blank=True)
    # 家庭住址
    address = models.CharField(max_length=100, null=True, blank=True)
    # 身份证号码
    id_number = models.CharField(max_length=18, null=True, blank=True)
    # 风险类型
    risk_type = models.CharField(max_length=10, null=True, blank=True)
    # 图片状态
    image_status = models.CharField(max_length=10, null=True, blank=True)
    def __str__(self):
        return self.name

    class Meta:
        db_table = 'user_auth'


# 用户详情数据
class UserDetailModel(models.Model):
    # 用户名字段，最大长度为50
    username = models.CharField(max_length=50, null=True, blank=True)
    # 头像
    avatar = models.CharField(max_length=255, null=True, blank=True)
    # 个性签名
    signature = models.CharField(max_length=255, null=True, blank=True)
    # 性别
    sex = models.CharField(max_length=10, null=True, blank=True)
    # 生日
    birthday = models.DateField(null=True, blank=True)
    # 地址
    address = models.CharField(max_length=36, null=True, blank=True)

    def __str__(self):
        return self.username
    class Meta:
        db_table = 'user_detail'



class UserModel(models.Model):
    # 密码字段，最大长度为50
    password = models.CharField(max_length=50)
    # 手机号字段，最大长度为12
    phone = models.CharField(max_length=12)
    # 关联实名认证
    auth = models.OneToOneField(UserAuthModel, on_delete=models.CASCADE, null=True, blank=True)
    # 用户详细信息
    detail = models.OneToOneField(UserDetailModel, on_delete=models.CASCADE, null=True, blank=True)
    # 定义数据库表名为user
    def __str__(self):
        return self.phone
    class Meta:
        db_table = 'user'
